home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
asm_n_z.zip
/
SWAPOUT.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-07-16
|
44KB
|
1,087 lines
; SWAP - (c) Copyright 1988 Nico Mak and Mansfield Software Group
; All rights reserved
;
; To rebuild SWAP.COM use the following instructions:
; masm swap;
; link swap;
; exe2bin swap swap.com
;
cr equ 13
lf equ 10
error macro message ;; macro to display an error message
local around, msg, msglen ;; and to jump to error_exit routine
jmp around
msg db &message,cr,lf ;; define error message
msglen equ $-msg
around:
mov dx,offset msg ;; get address of error message
mov cx,msglen ;; get length
jmp error_exit ;; jump to error exit routine
endm
; -------------------------------------------------------------------
; the following is copied over the swappee
; -------------------------------------------------------------------
code segment 'code'
assume cs:code,ds:code
org 100h ; org past psp
swap proc near
jmp begin
db 20 dup('STACK')
stack equ $
flag db 0 ; option flag
flag_copy equ 80h ; copy stdout to 'con'
flag_force equ 40h ; swap even if vector points to swappee
flag_quiet equ 20h ; don't print hello message
flag_disk equ 10h ; swap to disk
emsg_ems db "SWAP EMS Error "
ems_rc db 'xx function '
ems_func db 'xx',cr,lf
emsg_ems_len equ $-emsg_ems
my_psp dw ? ; segment of SWAP's original psp
swappee_psp dw ? ; segment of swappee's psp
; variables used when swapping to expanded memory
ems_handle dw ? ; emm handle
swap_pages dw ? ; number of pages for ems_handle
ems_frame dw ? ; ems page frame
last_ems_func db ? ; last emm function issued by swap
; variables used when swapping to disk
swap_fid db "c:\swap.dat",0 ; asciiz string to open swap file
swap_handle dw ? ; handle while swap file is open
; fields for int 21 function 4b (exec)
commandcom_addr dd ? ; address of program to exec (command.com)
exec_sp dw ? ; save area for reg clobbered by exec function
command_line db ?,"/c" ; command line for command.com
command_text db 130 dup (0) ; command line continued
blank_fcb db 36 dup (0) ; dummy fcb for exec function
exec_parm_block equ $ ; exec parameter block
exec_env dw ? ; segment addr of environment
cmdline_addr dw offset command_line ; address of command line
cmdline_seg dw ?
dw offset blank_fcb ; address of fcb
fcb1_seg dw ?
dw offset blank_fcb ; address of fcb
fcb2_seg dw ?
; fields used by int 21 handler
save_pid dw ? ; pid at time int 21 handler received control
int21_vector dd ? ; original int 21 vector owner
con db "con",0 ; asciiz string to open console
handle dw ? ; handle while "con" is open
char_buf db ? ; buffer for int 21 function 2 and 6 handlers
save_ax dw ? ; register save areas for int 21 handler
save_bx dw ?
save_cx dw ?
save_dx dw ?
save_ds dw ?
; -------------------------------------------------------------------
; run_command - the following code is copied over the swappee
; -------------------------------------------------------------------
run_command:
call copy_start ; start copying stdout to the console
call exec_user_cmd ; execute the user's command
call copy_stop ; stop copying stdout to the console
call swap_in ; swap in all but first 16k
retf
; -------------------------------------------------------------------
; subroutines for run_command follow
; -------------------------------------------------------------------
; -----
; copy_start - if -c option specified, open handle for console and hook int 21
; -----
copy_start:
test flag,flag_copy ; will we copy stdout to display?
jz copy_start_ret ; no
; ----- open a handle that points to "con"
mov dx,offset con ; address of asciiz file name
mov ax,3d01h ; code to open handle for writing
int 21h ; open the file
mov handle,ax ; remember handle
jnc open_worked ; did open succeed?
and flag,255-flag_copy ; no, then we won't copy stdout ...
jmp short copy_start_ret ; ... and won't hook int 21
open_worked:
; ----- hook int 21 vector
mov ax,3521h ; code to get interrupt 21 vector
int 21h ; ask dos for address in vector
mov word ptr int21_vector,bx; save offset
mov word ptr int21_vector[2],es ; save segment
mov dx,offset int21_handler ; address of our int 21 handler
mov ax,2521h ; code to set interrupt 21 address
int 21h ; tell dos to set int 21 vector
; ----- ensure that standard error is redirected and copied
mov al,cs:[19h] ; get stdout file handle array entry
mov cs:[1ah],al ; use stdout entry for stderr entry
copy_start_ret:
ret
; -----
; exec_user_cmd - set up and issue the int 21 function 4b (exec)
; -----
exec_user_cmd:
mov cs:exec_sp,sp ; save register
mov ax,cs:[2ch] ; pass address of our environment
mov exec_env,ax ; to exec function
mov word ptr cmdline_seg,ds ; address of command line
mov word ptr fcb1_seg,ds ; fill in segments for fcbs
mov word ptr fcb2_seg,ds
push cs
pop es
mov bx,offset exec_parm_block ; bx = exec parameter block
lds dx,commandcom_addr ; es:bx = asciiz string of command.com
mov ax,4b00h ; code to load and execute a program
int 21h ; tell dos to execute the user's program
mov ds,cs:swappee_psp ; restore ds addressability
cli ; turn off interrupts
mov ss,swappee_psp ; restore stack
mov sp,exec_sp
sti ; allow interrupts
ret
; -----
; copy_stop - close handle and restore original int 21 vector
; -----
copy_stop:
test cs:flag,flag_copy ; did we copy stdout to display?
jz copy_stop_ret ; no
; ----- close handle for console
mov bx,handle ; close handle for 'con'
mov ah,3eh ; dos function = close handle
int 21h ; tell dos to close 'con'
; ----- restore original int 21 vector
push ds ; ds gets clobbered, so save it
lds dx,int21_vector ; get address of old int 21 vector
mov ax,2521h ; code to set interrupt 21 address
int 21h ; tell dos to change it
pop ds ; restore ds addressability
copy_stop_ret:
ret
; -----
; swap_in - swap in all but the first page of swappee
; -----
swap_in:
mov bx,cs ; bx = swappee's psp
add bx,3ffh ; first page to swap in over
mov es,bx
test flag,flag_disk
jnz swap_in_disk
; ----- swap in from expanded memory
mov c